#include<iostream>
#include "string.h"

using namespace std;

int replaceSpaces(char ch[], int length){
	int count = 0;
	int originalLength = 0;
	int i = 0;
	while ( ch[i] != '\0' ){
		originalLength ++;
		if ( ch[i] == ' ' ){
			count ++;
		}
		i++;
	}
	cout << originalLength << endl;
	cout << "spaces count: " << count << endl;
	int newLength = originalLength + count * 2;
	if ( newLength > length ) return -1;
	int indexOfOriginal = originalLength;
	int indexOfNew = newLength;
	while ( indexOfOriginal >= 0 && indexOfNew > indexOfOriginal ){
		if ( ch[indexOfOriginal] == ' '){
			ch[indexOfNew--] = '0';
			ch[indexOfNew--] = '2';
			ch[indexOfNew--] = '%';
		}else {
			ch[indexOfNew--] = ch[indexOfOriginal];
		}
		indexOfOriginal --;
	}
	return newLength;
}

void printString(char ch[], int length){
	for ( int i=0; i<length; i++)
		cout << ch[i];
	cout << endl;
}

int main(void){
	const int length = 100;
	char ch[length] = "we are family";
	int newLength = replaceSpaces(ch, length);
	printString(ch, newLength);

	char * str = "we are family";
	int newl = replace(str,13);
	printString(str, newl);
	return 0;
}